{{Extend "layout"}}
{{Block "title"}}{{"数据库管理"|T}}{{/Block}}
{{Block "breadcrumb"}}
{{Include "db/logout_button"}}
{{Super}}
<li><a href="/db">{{"数据库管理"|T}}</a></li>
{{/Block}}
{{Block "head"}}
<link rel="stylesheet" type="text/css" href="__ASSETS__/js/jquery.nanoscroller/nanoscroller.css" />
<link rel="stylesheet" type="text/css" href="__ASSETS__/js/bootstrap.slider/css/slider.css" />
{{/Block}}
{{Block "bodyNav"}}
{{if Stored.Get "dbUsername"}}
  <div class="page-aside app codeditor tree">
      <a class="label label-primary collapsed-button"><i class="fa fa-angle-double-right"></i></a>
      <div class="fixed nano nscroller">
        <div class="content">
          <div class="header xs-padding-bottom no-padding-top">
            <button class="navbar-toggle" data-target=".app-nav" data-toggle="collapse" type="button">
              <span class="fa fa-chevron-down"></span>
            </button>
            <a class="label label-primary collapse-button"><i class="fa fa-angle-double-left"></i></a>
            <h2 class="page-title" title="{{Stored.Get "dbHost"}}">{{Stored.Get "dbHost"}}</h2>
            <p class="description">
            <span class="label label-default" title="{{Stored.Get "driver"}} {{Stored.Get "dbVersion"}}">
               {{Stored.Get "driver"}} {{Stored.Get "dbVersion"}}
            </span>
            </p>
            {{$dbList := Stored.Get "dbList"}}
            {{$dbName := Stored.Get "dbName"}}
            {{if $dbList}}
            <div class="input-group no-margin-bottom">
              <span class="input-group-addon">{{"数据库"|T}}</span>
              <select name="db" class="form-control" id="db">
                <option value="">{{"<未选择>"|}}</option>
                {{range $k,$v:=$dbList}}
                <option value="{{$v}}"{{if eq $dbName $v}} selected{{end}}>{{$v}}</option>
                {{end}}
              </select>
            </div>
            {{end}}
          </div> 
        <div class="app-nav collapse sm-line-height no-margin-top">
          <p class="title">{{"数据表"|T}}</p>
          {{if $dbName}}
          <ul class="nav nav-pills nav-stacked ">
              {{$tableList := Stored.Get "tableList"}}
              {{if $tableList}}
              {{$currentTable := Stored.table}}
              {{range $k,$v:=$tableList}}
              <li{{if eq $currentTable $v}} class="active"{{end}}>
                <a href="{{dbMgrURL "listData" $dbName $v}}" title="{{"查询"|T}}" class="fa fa-search {{Stored.operation}}"></a>
                <a href="{{dbMgrURL "viewTable" $dbName $v}}" title="{{$v}}">{{$v}}</a>
              </li>
              {{end}}
              {{end}}
          </ul>

          <div class="compose">
            <div class="btn-group">
            <a href="{{dbMgrURL "runCommand" $dbName}}" class="btn btn-flat btn-info">{{"SQL命令"|T}}</a>
            <a href="{{dbMgrURL "createTable" $dbName}}" class="btn btn-flat btn-primary">{{"创建表"|T}}</a>
            <a href="{{dbMgrURL "modifyDb" $dbName}}" class="btn btn-flat btn-success">{{"修改数据库"|T}}</a>
            </div>
          </div>
          {{end}}
        </div><!-- .app-nav -->
        </div>
        
      </div>
	</div>		
{{end}}
{{/Block}}

{{Block "main"}}
<div class="row">
    <div class="col-md-12">
        <div class="block-flat">
          <div class="header">							
            <h3>{{"连接数据库"|T}} <span style="font-size:15px">{{"或"|T}} <a href="/db/account">{{"从已保存的数据库账号中选择"|T}}</a></span></h3>
          </div>
          <div class="content">
              <form class="form-horizontal group-border-dashed" method="POST" action="">
                  
              <div class="form-group">
                <label class="col-sm-3 control-label">{{"系统"|T}}</label>
                <div class="col-sm-6">
                  {{$v := Form "driver"}}
                   <select class="form-control" name="driver">
                     {{range $k,$driverName:=Stored.Get "driverList"}}
                     <option value="{{$k}}"{{if eq $v $k}} selected{{end}}>{{$driverName}}</option>
                     {{end}}
                   </select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-3 control-label">{{"服务器"|T}}</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="host" value="{{Form "host"}}">
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-3 control-label">{{"用户名"|T}}</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="username" value="{{Form "username"}}">
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-3 control-label">{{"密码"|T}}</label>
                <div class="col-sm-6">
                    <input type="password" class="form-control" name="password" value="{{Form "password"}}" autocomplete="off">
                </div>
              </div>

              
              <div class="form-group">
                <label class="col-sm-3 control-label">{{"数据库"|T}}</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="db" value="{{Form "db"}}">
                </div>
              </div>

              <div class="form-group">
				<div class="col-sm-6 col-sm-offset-3">
                    <input type="hidden" name="operation" value="login">
          <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-sign-in"></i> {{"连接"|T}}</button>
          {{if Stored.user}}
				  <label class="radio-inline">
              {{$v := Form "remember"}}
              <input type="checkbox" value="1" name="remember" class="icheck"{{if or (eq $v "N") (eq $v "")}} checked{{end}}> {{"保存账号"|T}}
          </label>
          {{end}}
				</div>
			</div>
            </form>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
    </div>
</div>
{{/Block}}

{{Block "footer"}}
<script src="__ASSETS__/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script>
$(function(){
{{if Stored.Get "dbUsername"}}
      $(window).on('resize',function(){
          var fixedDiv=$(".page-aside div.fixed");
          if(!fixedDiv.find(".content > .header > .navbar-toggle").is(":visible")){
            fixedDiv.css({bottom:0,height:$(window).height()-50});
          }else{
            fixedDiv.css({height:'100%'});
          }
      }).trigger('resize');

      $('label.tree-toggler').click(function () {
        var icon = $(this).children(".fa");
        if(icon.hasClass("fa-folder-o")){
          icon.removeClass("fa-folder-o").addClass("fa-folder-open-o");
        }else{
          icon.removeClass("fa-folder-open-o").addClass("fa-folder-o");
        }        

        $(this).parent().children('ul.tree').toggle(300,function(){
          $(this).parent().toggleClass("open");
          $(".tree .nscroller").nanoScroller({ preventPageScrolling: true });
          $(window).trigger('resize');
        });
        
      }).trigger('click');
  
      $('#db').on('change',function(){
        var db=$(this).val();
        if(db){
          window.location='{{dbMgrURL "listTable"}}&db='+db;
        }else{
          window.location='{{dbMgrURL "listDb"}}';
        }
      });
      $('#sidebar-collapse').trigger('click');
      App.pageAside();
      App.tableReponsiveInit();
{{end}}
});
</script>
{{/Block}}